﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for DBData
/// </summary>
public class DBData : DatabasePage
{
	public DBData()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    //Connections
    public static DataTable Connections(object userId)
    {
        return DataAccess.GetDataTable(DataAccess.ConfigurationConnectionString, Query.ConnectionList(userId));
    }

    //Queries
    public static DataTable Queries(int connectionId)
    {
        return DataAccess.GetDataTable(DataAccess.ConfigurationConnectionString, Query.Queries(connectionId));
    }


    public static DataTable Mappings(int connectionId)
    {
        return DataAccess.GetDataTable(DataAccess.ConfigurationConnectionString, Query.MappingList(connectionId));
    }
    
    //Views and tables form db
    public static DataTable DatabaseObjects(object connectionString, DatabaseObjectTypes dot)
    {
        return DataAccess.GetDataTable(connectionString.ToString(), Query.ObjectTypes(dot));
    }

    public static DataTable SampleRow(object connectionString, string tableName)
    {
        string selectStr = string.Format("SELECT TOP 1 * FROM {0}", tableName);
        DataTable dt = DataAccess.GetDataTableSchema(connectionString.ToString(), selectStr);
        return dt;
    }

    public static DataRow ItemRow(object connectionString, string tableName, string idColumn, string idValue)
    {
        string selectStr = string.Format("SELECT TOP 1 * FROM {0} WHERE {1}={2}", tableName, idColumn, idValue);
        return DataAccess.GetDataRow(connectionString.ToString(), selectStr);
    }

}